<?php

function getLPointDatas($lpoint_file = 'ephL5.sph')
{
  global $config;
  $content = file_get_contents(BASE_PATH . $config['input']['path'].'/'.$lpoint_file);
}

function getDatasFromFitFile($fit_file)
{
  global $m_amount, $config;
  $content = file_get_contents($fit_file);
  $tmp = explode("Catalog of objects", $content);
  $strings = explode("\n", $tmp[1]);
  for($i = 0; $i < count($strings); $i ++)
  {
    if (eregi("Mean", $strings[$i]))
    {
      $t_amount = $i;
    }
  }
  $t_amount -= 2;
  $temp = explode("|", $strings[4]);
  for($i = 0; $i < count($temp); $i ++)
  {
    $amounts[$i] = strlen($temp[$i]) + 1;
  }
  $amount = count($temp);
  for($i = 6; $i < $t_amount; $i ++)
  {
    $tmp2 = 0;
    $next = 0;
    for($j = 0; $j < $amount; $j ++)
    {
      $previous = $next;
      $next += $amounts[$j];
      $results[$i][$j] = str_replace("  ", " ", trim(substr($strings[$i], $previous, $amounts[$j])));
    }
  }
  $position = $config['input']['position'];
  for($i = 7; $i < $t_amount; $i ++)
  {
    $tmp = $results[$i][$position];
    $tmp2 = explode(" ", $tmp);
    $first[$i - 6] = $tmp2[0];
    if (isset($tmp2[1]))
    {
      $first_error[$i - 6] = $tmp2[1];
    } else
    {
      $first_error[$i - 6] = $tmp2[2];
    }
    if (isset($tmp2[count($tmp2) - 2]))
    {
      $second[$i - 6] = $tmp2[count($tmp2) - 2];
      $second_error[$i - 6] = $tmp2[count($tmp2) - 1];
    } else
    {
      $second[$i - 6] = 0;
      $second_error[$i - 6] = 0;
    }
    
    $tmp = explode(" ", $results[$i][5]);
    if ((isset($tmp[0])) and (isset($tmp[1])))
    {
      $names[$i - 6] = $tmp[0] . " " . $tmp[1];
    } else
    {
      $names[$i - 6] = 0;
    }
  }
  $m_amount = $t_amount;
  return array ($first, $first_error, $second, $second_error, $names );
}


?>